/*****************************************************************************
	SNEGA UTILITIES 0.7a
	Copyright (C) 2009, Xiaohan Tian (snega0223)
	
	http://code.google.com/p/snega-utilities/
	
	This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License(LGPL) as
	published by the Free Software Foundation, either version 3 of the 
	License, or(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.
	
	You should have received a copy of the GNU Lesser General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/

package org.sng.util.db;

import java.sql.*;

public class DbConn {
	
	public Connection	con		= null;
	public Statement	stmt	= null;
	public ResultSet	rs		= null;
	public DatabaseMetaData dmd	= null;
	
	public static DbConn get()
	{
		//System.out.println("!! - DbConn - Instance generated.");
		
		return new DbConn();
	}
	
	public boolean close()
	{
		try
		{
			//System.out.println("!! - DbConn - Instance released.");
			
			attemptClose(rs);
			attemptClose(con);
			attemptClose(stmt);
		}
		catch (Exception e)
		{
			e.printStackTrace();
			return false;
		}
		
		return true;
	}
	
	static void attemptClose(ResultSet o)
    {
		try
		    { if (o != null) o.close();}
		catch (Exception e)
		    { e.printStackTrace();}
    }
	
	static void attemptClose(Statement o)
    {
		try
		    { if (o != null) o.close();}
		catch (Exception e)
		    { e.printStackTrace();}
    }

    static void attemptClose(Connection o)
    {
		try
		    { if (o != null) o.close();}
		catch (Exception e)
		    { e.printStackTrace();}
    }

}
